from PyQt5.QtWidgets import QMessageBox

from src.admin.SelectKind_UI import Ui_Form
from PyQt5 import QtWidgets
from src.admin.KindMsgAlter_win import KindMsgAlter_Win
from src.admin.AllKinds_win import AllKinds_Win



class SelectKind_Win(QtWidgets.QMainWindow,Ui_Form):
    def __init__(self,mydb, parent=None):
        super(SelectKind_Win, self).__init__(parent=parent)
        #ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('')
        #self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
        #self.setWindowIcon(icon)
        self.setupUi(self)
        self.mydb=mydb

        self.KindMsg_form=KindMsgAlter_Win(self.mydb)
        self.AllKinds_form=AllKinds_Win(self.mydb)

        self.KindMsg_form.setWindowTitle("玩具种类管理")
        self.AllKinds_form.setWindowTitle("全部种类信息")

    def myKindMsg(self):
        s = self.lineEdit.text()
        s = str(s)
        myselect = "SELECT * FROM 玩具种类表 WHERE 玩具种类号= " + s
        try:
            mycursor = self.mydb.cursor()
            mycursor.execute(myselect)
        except Exception as a:
            QMessageBox.critical(self, '错误', '信息不正确')
        else:
            result = mycursor.fetchall()
            if len(result) == 0:
                QMessageBox.critical(self, '错误', '请输入正确的玩具种类号')
            else:
                self.KindMsg_form.label_5.setText(str(result[0][0]))
                self.KindMsg_form.label_9.setText(result[0][1])
                self.KindMsg_form.label_12.setText(result[0][2])
                self.KindMsg_form.label_14.setText(str(result[0][3]))
                self.KindMsg_form.label_16.setText(str(result[0][4]))
                self.KindMsg_form.show()


    def myAllKinds(self):
        self.AllKinds_form.myTable_init()
        self.AllKinds_form.show()

    def myOut(self):
        self.hide()

    def getmydb(self,mydb):
        self.mydb=mydb
        self.KindMsg_form.getmydb(mydb)
        self.AllKinds_form.getmydb(mydb)